package com.mzj.saas.mservice.oss.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.oss.service.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 阿里云OSS对象存储
 *
 * @author shun
 * @createDate: 2021年3月24日 下午4:48:05
 * @version: 1.0
 */
@Controller
@RequestMapping("/oss")
public class OSSController {
    @Autowired
    private OSSService OSSService;

    /**
     * 文件上传
     *
     * @param mfile
     * @param bucketName
     * @param type
     * @return
     * @author shun
     * @date 2021年3月24日
     */
    @PostMapping(value = "/file/{type}")
    @ResponseBody
    public ResultBean<Object> putFile(@RequestParam("file") MultipartFile file, @PathVariable String type) {
        return OSSService.putFile(null, file, type);
    }

    /**
     * 文件删除
     *
     * @param fileKey
     * @param bucketName
     * @return
     * @author shun
     * @date 2021年3月24日
     */
    @DeleteMapping(value = "/file")
    @ResponseBody
    public ResultBean<Object> deleteObject(@RequestParam(required = true) String fileKey) {
        return OSSService.deleteObject(null, fileKey);
    }

    @GetMapping(value = "/getObjectFile")
    @ResponseBody
    public void getObjectFile(@RequestParam String path) {
        OSSService.getObjectFile("", path);
    }


}
